import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-03-02
 * Time: 10:38
 */
public class twoSum {
    public static class ListNode {
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
            next = null;
        }
    }

    public static ListNode two(ListNode head1,ListNode head2) {
        ListNode dummyHead = new ListNode(0);
        ListNode cur = dummyHead;
        ListNode cur1 = head1;
        ListNode cur2 = head2;
        int t = 0;

        while(cur1 != null || cur2 != null || t != 0) {
            if(cur1 != null) {
                t += cur1.val;
                cur1 = cur1.next;
            }
            if(cur2 != null) {
                t += cur2.val;
                cur2 = cur2.next;
            }
            cur.next = new ListNode(t % 10);
            t = t / 10;
            cur  = cur.next;
        }
        return  dummyHead.next;
    }

    public static  void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 读取第一链表长度
        int n1 = sc.nextInt();
        ListNode head1 = null;
        ListNode tail1 = null;

        for(int i = 0; i < n1; i++) {
            int val  = sc.nextInt();
            ListNode newNode = new ListNode(val);
            if(head1 == null) {
                head1 = newNode;
                tail1 = newNode;
            } else {
                tail1.next = newNode;
                tail1 = newNode;
            }
        }

        // 读取第2个链表长度
        int n2 = sc.nextInt();
        ListNode head2 = null;
        ListNode tail2 = null;

        for(int i = 0; i < n2; i++) {
            int val  = sc.nextInt();
            ListNode newNode = new ListNode(val);
            if(head2 == null) {
                head2 = newNode;
                tail2 = newNode;
            } else {
                tail2.next = newNode;
                tail2 = newNode;
            }
        }

        // 打印结果
        ListNode h = two(head1,head2);

        while(h != null) {
            System.out.print(h.val + " ");
            h = h.next;
        }
    }
}



